package com.example.demo.dao;

import com.example.demo.Enity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.ArrayList;

public interface UserJpa extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User> {

    @Query(nativeQuery = true, value = "select * from user where yb_userid=?1")
    ArrayList<User> isExist(String avid);

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "insert into user(yb_schoolname,yb_userhead,yb_userid,yb_usernick) value(?1,?2,?3,?4)")
    void addUser(String yb_schoolname, String yb_userhead, String yb_userid, String yb_usernick);

    @Query(nativeQuery = true, value = "select * from user where yb_userid=?1 and password=?2")
    ArrayList<User> loginApp(String username, String password);

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "insert into user(yb_userid,password,yb_usernick,yb_userhead) value(?1,?2,?3,?4)")
    void registerApp(String username,String password,String nickname,String headimg);
    //检测是否出现相同账号
    @Query(nativeQuery = true, value = "select * from user where yb_userid=?1")
    ArrayList<User> findsum(String username);

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "update user set yb_usernick=?2 where yb_userid=?1")
    void updateName(String username,String nickname);

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "update user set yb_userhead=?2 where yb_userid=?1")
    void updateImg(String username,String img);
}
